package unl.cse.labs.lab02;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class ChildCredit {

	public static void main(String args[]) {
		Child tom = new Child("Tommy", 14);
		Child dick = new Child("Richard", 12);
		Child harry = new Child("Harold", 21);
		
		Child arr[] = new Child[3];
		arr[0] = tom;
		arr[1] = dick;
		arr[2] = harry;
		
		
		//TODO: write a loop to iterate over the elements in the child array 
		//      and output a table as specified
		System.out.println("Child\t\tAmount");
		
		int total =0;
		
		List <Integer> credit = new ArrayList<Integer>();
		
		String result1 = String.format("%.2f", 1000.00);
		String result2 = String.format("%.2f", 500.00);
		String result3 = String.format("%.2f", 0.00);
		
		if(arr[0].getAge()<18){
			credit.add(1000);
			
			System.out.println(arr[0].getName()+"("+arr[0].getAge()+")\t$"+result1);
					
		}
		
		
		for (int i=1;i<arr.length; i++){
			if(arr[i].getAge() < 18){
				credit.add(500);
				System.out.println(arr[i].getName()+"("+arr[i].getAge()+")\t$"+result2);
				
			}else{
				credit.add(0);
				System.out.println(arr[i].getName()+"("+arr[i].getAge()+")\t$"+result3);
			}
			
			
		}
		
		DecimalFormat f = new DecimalFormat("######.00");
		
		for(Integer element : credit){
			total = total + element;
			
		}
		
		System.out.println("Total credit: \t$" +f.format(total));
	}
}
